package org.example.everyday;


import java.util.HashSet;
import java.util.Set;

/**
 * <p>
 * Description:TODO 详细描述
 * <p>
 * <p>
 *
 * @author anlu
 * @date 2022/4/21 0021 22:36
 */
public class Lc824 {
    public static void main(String[] args) {
        Lc824 lc824 = new Lc824();

        String sentence = "I speak Goat Latin";
        String res = lc824.toGoatLatin(sentence);
        System.out.println(res);

    }

        public String toGoatLatin(String sentence) {
            Set<Character> vowels = new HashSet<Character>() {{
                add('a');
                add('e');
                add('i');
                add('o');
                add('u');
                add('A');
                add('E');
                add('I');
                add('O');
                add('U');
            }};


            int n = sentence.length();
            int i = 0, cnt = 1;
            StringBuffer ans = new StringBuffer();

            while (i < n) {
                int j = i;
                while (j < n && sentence.charAt(j) != ' ') {
                    ++j;
                }

                ++cnt;
                if (cnt != 2) {
                    ans.append(' ');
                }
                if (vowels.contains(sentence.charAt(i))) {
                    ans.append(sentence.substring(i, j));
                } else {
                    ans.append(sentence.substring(i + 1, j));
                    ans.append(sentence.charAt(i));
                }
                ans.append('m');
                for (int k = 0; k < cnt; ++k) {
                    ans.append('a');
                }

                i = j + 1;
            }

            return ans.toString();

    }


}
